﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using Husb.Data;
using Husb.Util;
using CentralOffice.Task.Data;
using CentralOffice.Task.DataAccess;

using ApprovalTable = CentralOffice.Task.Data.ApprovalDataSet.ApprovalsDataTable;
using ApprovalRow = CentralOffice.Task.Data.ApprovalDataSet.ApprovalsRow;

namespace CentralOffice.Task.BusinessActions
{
    public class Approvals : DataAccessManager<ApprovalDataSet, ApprovalTable, ApprovalRow, ApprovalAdapter>
    {
        public static ApprovalRow GetFirstReply(Guid applicationId)
        {
            ApprovalAdapter adapter = new ApprovalAdapter();
            return adapter.GetFirstStep(applicationId);
        }

        public static ApprovalRow GetByPreviousStepId(Guid approvalId)
        {
            ApprovalAdapter adapter = new ApprovalAdapter();
            return adapter.GetByPreviousStepId(approvalId);
        }

        public static ApprovalRow GetRejectedStep(Guid applicationId)
        {
            ApprovalAdapter adapter = new ApprovalAdapter();
            return adapter.GetRejectedStep(applicationId);
        }

        public static int DeleteByPreviousStepId(Guid approvalId)
        {
            ApprovalAdapter adapter = new ApprovalAdapter();
            return adapter.DeleteByPreviousStepId(approvalId);
        }

        public static int DeleteByApplicationId(Guid applicationId)
        {
            ApprovalAdapter adapter = new ApprovalAdapter();
            return adapter.DeleteByApplicationId(applicationId);
        }

        public static DataView GetApprovalTimeSpan( decimal deduct, DateTime start, DateTime end, string sortExpression)//int delay,
        {
            ApprovalAdapter adapter = new ApprovalAdapter();
            DataTable dt = adapter.GetApprovalTimeSpan( deduct, start, end);//delay,

            if (String.IsNullOrEmpty(sortExpression))
                return new DataView(dt, null, "ElapsedTime DESC", DataViewRowState.CurrentRows);
            else
                return new DataView(dt, null, sortExpression, DataViewRowState.CurrentRows);
        }
    }
}
